Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use node interface pointers in the TransformListener class #100

Closed
wants to merge 2 commits into from

Conversation

lbegani
Copy link

@lbegani lbegani commented Apr 5, 2019

In the TransformListener class, use node interfaces instead of using the node directly so that the code works with either rclcpp::Node or rclcpp_lifecycle::LifecycleNode. Retain the existing node-based interface for backwards compatibility.
This change fixes the issue reported here - #94

Lalit Begani added 2 commits April 4, 2019 11:05
In the TransformListener class, use node interfaces instead of using the node directly
so that the code works with either rclcpp::Node or rclcpp_lifecycle::LifecycleNode.
Retain the existing node-based interface for backwards compatibility.
@tfoote tfoote added the in review Waiting for review (Kanban column) label Apr 5, 2019
@lbegani
Copy link
Author

lbegani commented Apr 5, 2019

@tfoote @mjeronimo - Kindly review.

@tfoote tfoote self-requested a review April 5, 2019 20:50
@mjeronimo
Copy link
Contributor

@lbegani Looks good to me.

@tfoote - One unfortunate consequence of ROS2's use of the interface pointers is that there is code duplication across the various classes that use these interfaces. For example, when creating a subscription, the topics interface itself isn't enough; there are templates on top of this required to get a memory strategy, etc. See:

  • TransformListener::create_subscription (this PR)
  • Node::create_subscription
  • LifecycleNode::create_subscription
  • Any other class that receives a topics interface and creates a subscription with it

Perhaps these templates could be factored out somehow so that they could be used by any class that uses the topics interface (likewise with other interfaces that require addition "glue" templates).

@wjwwood
Copy link
Member

wjwwood commented Apr 13, 2019

Perhaps these templates could be factored out somehow so that they could be used by any class that uses the topics interface (likewise with other interfaces that require addition "glue" templates).

I'm working on something like this for another feature, see:

And it being used:

As a result, the UnusedParametersChecker class can take any struct or class that has the appropriate method to get the required interface (in this case the NodeParameterInterface.

I think a similar pattern could be provided for each node interface, and used in cases like this to decouple these classes from rclcpp::Node without having to have too much boilerplate.

@mjeronimo
Copy link
Contributor

mjeronimo commented Apr 15, 2019

@wjwwood @tfoote @lbegani How about we get this one integrated and then create another PR for the factoring-out work?

Copy link
Contributor

@Karsten1987 Karsten1987 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of changes I'd like to have changed. Passing the shared pointer by value and re-using the rclcpp::create_subscription free function.

I am not sure about the priority of this package, but having these changes in for the dashing API freeze would be a great thing.

TransformListener(tf2::BufferCore & buffer, bool spin_thread = true);

TF2_ROS_PUBLIC
TransformListener(tf2::BufferCore & buffer, rclcpp::Node::SharedPtr nh, bool spin_thread = true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be up for discussion, but I advocate for removing this constructor completely and thus force the usage of the node interfaces.


return rclcpp::create_subscription<MessageT, CallbackT, Alloc, CallbackMessageT, SubscriptionT>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not calling this function directly?

TransformListener(tf2::BufferCore& buffer, rclcpp::Node::SharedPtr nh, bool spin_thread = true);
TransformListener(
tf2::BufferCore & buffer,
const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr & node_base,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't pass a shared pointer by reference.

/// Initialize this transform listener, subscribing, advertising services, etc.
void init();
void initThread();

template<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this signature should not be necessary. Including this header file should be enough


TransformListener::TransformListener(
tf2::BufferCore & buffer,
const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr & node_base,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't pass a shared pointer by reference

buffer_.setUsingDedicatedThread(true);
}

template<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as before.

const tf2_msgs::msg::TFMessage & msg_in = *msg;
// TODO(tfoote) find a way to get the authority
std::string authority = "Authority undetectable"; // msg_evt.getPublisherName(); // lookup the authority
for (unsigned int i = 0; i < msg_in.transforms.size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: for (auto i = 0u; ..)

@Karsten1987
Copy link
Contributor

in order to push this forward into dashing API freeze, I've opened #108 which is based on top of this PR. It's up for review

@tfoote
Copy link
Contributor

tfoote commented May 10, 2019

Replaced by #108

@tfoote tfoote closed this May 10, 2019
@tfoote tfoote removed the in review Waiting for review (Kanban column) label May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants